import 'package:tender_flutter/page/goods/model/goods_entity.dart';

goodsEntityFromJson(GoodsEntity data, Map<String, dynamic> json) {
	if (json['pageNum'] != null) {
		data.pageNum = json['pageNum'] is String
				? int.tryParse(json['pageNum'])
				: json['pageNum'].toInt();
	}
	if (json['pageSize'] != null) {
		data.pageSize = json['pageSize'] is String
				? int.tryParse(json['pageSize'])
				: json['pageSize'].toInt();
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? int.tryParse(json['total'])
				: json['total'].toInt();
	}
	if (json['pages'] != null) {
		data.pages = json['pages'] is String
				? int.tryParse(json['pages'])
				: json['pages'].toInt();
	}
	if (json['list'] != null) {
		data.xList = new List<GoodsList>();
		(json['list'] as List).forEach((v) {
			data.xList.add(new GoodsList().fromJson(v));
		});
	}
	if (json['isFirstPage'] != null) {
		data.isFirstPage = json['isFirstPage'];
	}
	if (json['isLastPage'] != null) {
		data.isLastPage = json['isLastPage'];
	}
	return data;
}

Map<String, dynamic> goodsEntityToJson(GoodsEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['pageNum'] = entity.pageNum;
	data['pageSize'] = entity.pageSize;
	data['total'] = entity.total;
	data['pages'] = entity.pages;
	if (entity.xList != null) {
		data['list'] =  entity.xList.map((v) => v.toJson()).toList();
	}
	data['isFirstPage'] = entity.isFirstPage;
	data['isLastPage'] = entity.isLastPage;
	return data;
}

goodsListFromJson(GoodsList data, Map<String, dynamic> json) {
	if (json['priceO'] != null) {
		data.priceO = json['priceO'] is String
				? int.tryParse(json['priceO'])
				: json['priceO'].toInt();
	}
	if (json['priceN'] != null) {
		data.priceN = json['priceN'] is String
				? int.tryParse(json['priceN'])
				: json['priceN'].toInt();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['detail'] != null) {
		data.detail = json['detail'].toString();
	}
	if (json['pic'] != null) {
		data.pic = json['pic'].toString();
	}
	if (json['title'] != null) {
		data.title = json['title'].toString();
	}
	return data;
}

Map<String, dynamic> goodsListToJson(GoodsList entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['priceO'] = entity.priceO;
	data['priceN'] = entity.priceN;
	data['id'] = entity.id;
	data['detail'] = entity.detail;
	data['pic'] = entity.pic;
	data['title'] = entity.title;
	return data;
}

goodsFromJson(Goods data, Map<String, dynamic> json) {
	if (json['IS'] != null) {
		data.isShow = json['IS'];
	}
	if (json['code'] != null) {
		data.code = json['code'] is String
				? int.tryParse(json['code'])
				: json['code'].toInt();
	}
	return data;
}

Map<String, dynamic> goodsToJson(Goods entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['IS'] = entity.isShow;
	data['code'] = entity.code;
	return data;
}